package com.example.homework.bean;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;

import androidx.core.app.NotificationCompat;
import androidx.core.app.NotificationManagerCompat;

import com.example.homework.R;

public class TodoReminderReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        int todoId = intent.getIntExtra("todoId", -1);
        showNotification(context, todoId);
    }

    private void showNotification(Context context, int todoId) {
        NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context);

        // 创建通知（需在 AndroidManifest.xml 中声明通知渠道）
        NotificationCompat.Builder builder = new NotificationCompat.Builder(context, "todo_reminder")
                .setSmallIcon(R.drawable.ic_notification)
                .setContentTitle("待办提醒")
                .setContentText("您有一个待办事项需要处理")
                .setPriority(NotificationCompat.PRIORITY_DEFAULT)
                .setAutoCancel(true); // 点击后自动清除通知

        notificationManager.notify(todoId, builder.build());
    }
}
